// 将两个有序顺序表合并为一个新的有序顺序表，并由函数返回结果顺序表。
#pragma once
#include "vector"
#include "iostream"

void combineAB2C(std::vector<int> &A, std::vector<int> &B, std::vector<int> &C)
{
    int iA = 0, iB = 0, iC = 0;
    C.resize(10000);
    while (iA < A.size() && iB < B.size())
    {
        if (A[iA] > B[iB])
        {
            C[iC] = B[iB];
            iB++;
        }
        else
        {
            C[iC] = A[iA];
            iA++;
        }
        iC++;
    }
    for (; iA < A.size(); iA++)
    {
        C[iC] = A[iA];
        iA++;
        iC++;
    }
    for (; iB < B.size(); iB++)
    {
        C[iC] = B[iB];
        iB++;
        iC++;
    }
    C.resize(iC);
    std::cout << "Csize " << C.size() << "\r\n";
}

int main()
{
    std::vector<int> vec1, vec2, vec3;

    //init data
    for (int i = 0; i < 100; i++)
    {
        if (i % 2 == 0)
        {
            if (i < 50)
            {

                vec1.push_back(i);
            }
        }
        else
        {
            vec2.push_back(i);
        }
    }
    for (int i = 0; i < vec1.size(); i++)
    {
        std::cout << vec1[i] << ",";
    }
    std::cout << "\r\n";
    for (int i = 0; i < vec2.size(); i++)
    {
        std::cout << vec2[i] << ",";
    }
    std::cout << "\r\n";
    ///////////////////////////////////////////////////
    combineAB2C(vec1, vec2, vec3);
    for (int i = 0; i < vec3.size(); i++)
    {
        std::cout << vec3[i] << ",";
    }
    std::cout << "\r\n";
    return 0;
}